package com.jen.controller;

import com.google.gson.Gson;
import com.jen.dto.DelayedMessageDTO;
import com.jen.queue.DelayedMessageQueueConfig;
import com.jen.queue.DelayedMessageQueueOtherConfig;
import com.jen.service.RabbitSendService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @ClassName TestRabbitMQController
 * @Description rabbitmq 测试
 * @Date 2021/12/17 11:50
 * @Author Rick Jen
 */
@RestController
@RequiredArgsConstructor
@RequestMapping(value = "/test")
public class TestRabbitMQController {

    private final RabbitSendService rabbitSendService;

    /**
     * @Description 测试延时队列
     * @author Rick Jen
     * @Date 2021/12/17 15:48
     * @Param dto 消息体数据
     * @Param delayTime 过期时间 单位毫秒
     */
    @RequestMapping(value = "/sendOtherDelayedMessage")
    public String sendOtherDelayedMessage(DelayedMessageDTO dto, Long delayTime) {
        rabbitSendService.sendOtherDelayMessage(DelayedMessageQueueOtherConfig.DELAYED_OTHER_EXCHANGE,DelayedMessageQueueOtherConfig.DELAYED_OTHER_ROUTING_KEY, delayTime, new Gson().toJson(dto));
        return "发送成功！";
    }

    /**
     * @Description 测试延时队列
     * @author Rick Jen
     * @Date 2021/12/17 14:02
     * @Param dto 消息体数据
     * @Param delayTime 过期时间 单位毫秒
     */
    @RequestMapping(value = "/sendDelayedMessage")
    public String sendDelayedMessage(DelayedMessageDTO dto, Long delayTime) {
        rabbitSendService.sendDelayMessage(DelayedMessageQueueConfig.DELAYED_QUEUE, delayTime, new Gson().toJson(dto));
        return "发送成功！";
    }
}
